import random

def guess_number_game():
    # 生成一个1到100之间的随机整数
    number_to_guess = random.randint(1, 100)
    attempts = 0
    guessed = False

    print("欢迎来到猜数字游戏！我已经想好了一个1到100之间的数字，快来猜一猜吧！")

    while not guessed:
        try:
            # 获取用户输入
            user_guess = int(input("请输入你猜的数字: "))
            attempts += 1

            if user_guess < number_to_guess:
                print("太小了，再试一次！")
            elif user_guess > number_to_guess:
                print("太大了，再试一次！")
            else:
                guessed = True
                print(f"恭喜你，猜对了！你一共猜了 {attempts} 次。")
        except ValueError:
            print("请输入一个有效的数字！")

if __name__ == "__main__":
    guess_number_game()
